package com.hzncc.scaffold.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.hzncc.scaffold.entity.Other.Applianceapply;
import com.hzncc.scaffold.entity.Vo.AllianceUnit;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 机构申请表 Mapper 接口
 * </p>
 *
 * @author DrunkBear
 * @since 2022-04-27
 */
public interface ApplianceapplyMapper extends BaseMapper<Applianceapply> {

    @Select("SELECT\n" +
            "\t`applianceapply`.`id`,\n" +
            "\t`applianceapply`.`status`,\n" +
            "\t`applianceapply`.`pubTime`,\n" +
            "\t`applianceapply`.`createTime`,\n" +
            "\t`applianceapply`.`stayAtTop`,\n" +
            "\t`institute`.`id` AS `instituteId`,\n" +
            "\t`institute`.`name` AS `instituteName`,\n" +
            "\t`institute`.`role` AS `instituteRole`,\n" +
            "\t`publisher`.`id` AS `publisherId`,\n" +
            "\t`publisher`.`name` AS `publisherName` \n" +
            "FROM\n" +
            "\t`applianceapply` AS `allianceApply`\n" +
            "\tLEFT OUTER JOIN `user` AS `institute` ON `allianceApply`.`instituteId` = `institute`.`id`\n" +
            "\tLEFT OUTER JOIN `user` AS `publisher` ON `allianceApply`.`publisherId` = `publisher`.`id`\n" +
            "ORDER BY\n" +
            "\t`applianceapply`.`stayAtTop` DESC,\n" +
            "\t`applianceapply`.`sortTime` DESC,\n" +
            "\t`applianceapply`.`id` DESC\n" +
            "\t\n" +
            "\t\n")
    public List<AllianceUnit> listTest(@Param(Constants.WRAPPER)LambdaQueryWrapper lambdaQueryWrapper);


    @Select("SELECT applianceapply.instituteId FROM `applianceapply`")
    public List<Integer> instituteIdList();


    @Select("SELECT\n" +
            "\tapplianceapply.*,\n" +
            "\tuser.`name` As userName\n" +
            "FROM\n" +
            "\t`applianceapply`\n" +
            "LEFT JOIN `user` ON applianceapply.instituteId = user.id ${ew.customSqlSegment}")
    public  List<Applianceapply> listVo(@Param(Constants.WRAPPER)QueryWrapper queryWrapper);
}
